package org.ovirt.microvirt.services.events.impl;

import java.util.HashMap;
import java.util.Map;

import org.ovirt.microvirt.services.events.BeansLookup;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class SpringBeanLookup implements BeansLookup, ApplicationContextAware {

	public SpringBeanLookup(final Map<String, String> beanNames) {
		super();
		this.beanNames = beanNames;
	}

	ApplicationContext context;
	final Map<String, String> beanNames;

	@Override
	public Map<String, Object> lookupAll() {
		HashMap<String, Object> ret = new HashMap<String, Object>();
		for (Map.Entry<String, String> entry : beanNames.entrySet()) {
			ret.put(entry.getValue(), context.getBean(entry.getKey()));
		}
		return ret;
	}

	@Override
	public void setApplicationContext(
			final ApplicationContext applicationContext) throws BeansException {
		this.context = applicationContext;
	}

}
